const express = require('express')
const router = express.Router()
const multer = require('multer')
const upload = multer({dest:'./userimg'})
const cookieParser = require('cookie-parser')
const {checkToken} = require('../middleware/middleware')
const {register,login,userInfo,userEdit,userpass,userhead,reglogCode,userEmail,confirmcode,loadpasss} = require('../controller/user')

// 验证码接口
router.get('/api/reglogCode',cookieParser(),reglogCode)

// 注册接口
router.post('/api/register',register)

// 登录接口
router.post('/api/login',login)

// 获取用户信息接口
router.get('/api/list/:id',checkToken,userInfo)

// 用户信息修改接口
router.post('/api/edit/:id',checkToken,userEdit)

// 修改用户密码接口
router.post('/api/pass/:id',checkToken,userpass)

// 修改用户头像接口
router.post('/api/userhead/:id',upload.single('image'),checkToken,userhead)

// 邮箱发送验证码接口
router.post('/api/Email',userEmail)

// 确认验证码是否正确
router.post('/api/confirmcode',confirmcode)

// 找回密码接口
router.post('/api/loadpasss/:id',loadpasss)

module.exports = router